package com.tim.javaApi;

import java.io.*;
import java.nio.channels.*;

public class FileAndResource {

    /**
     * 相对路径
     */
    public static void relativePath(){
        // 项目根路径
        new File("").getAbsolutePath();
        // classpath；pom-Resources配置打包时输出
        FileAndResource.class.getClassLoader().getResource("");
        // class文件路径
        FileAndResource.class.getResource("");
    }

    /**
     *
     */
    public static void zeroCopy() throws Exception {
        FileChannel fc = null;
        // mmap。创建后不依赖fc，小文件时效率低于fc.read
        fc.map(FileChannel.MapMode.READ_WRITE, 0, 0);
        // sendfile?
        fc.transferFrom(null, 0, 0);
        fc.transferTo(0, 0, null);
    }

    /**
     *
     */
    public static void io(){
        InputStream is;
        OutputStream os;
        {
            FileInputStream fis;
            BufferedInputStream bis;
            ByteArrayInputStream bais;// String转InputStrream
            PipedInputStream pis;// 管道，is转os
        }
        Reader reader;
        Writer writer;
        {
            FileReader fr;
            BufferedReader br;
            StringReader sr;
            CharArrayReader car;
            PipedReader pr;
            InputStreamReader isr;

        }


    }

    /**
     *
     */
    public static void nio(){
        Channel channel;

        SelectableChannel sc;// 网络通信
        FileChannel fc;// 磁盘映射

    }

    /**
     *
     */
    public static void aio(){
        AsynchronousChannel ac;
    }
}
